﻿using B.Z.BasicData.API.Read.Application.Role;
using B.Z.BasicData.API.Read.Application.User;
using B.Z.BasicData.API.Read.DTO;
using B.Z.BasicData.Domain.Entity.Authorize;
using B.Z.BasicData.ErrorCode;
using Common;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.XSSF.Streaming.Values;
using System.Security.Claims;

namespace B.Z.BasicData.API.Read.Controllers
{
    /// <summary>
    /// 控制器-读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ManageController : ControllerBase
    {
        private readonly IMediator mediator;

        public ManageController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>

        [HttpGet]
        [AllowAnonymous]
        public Task<APIResult<LoginDto>> Login([FromQuery] LoginQueryCommand command)
        {
            string idstring = "130634200411153135";
            idstring.GetBithByCardId();

            

            return mediator.Send(command);
        }
        /// <summary>
        /// 获取省份
        /// </summary>
        /// <returns></returns>

        [HttpGet]
        public Task<APIResult<List<T_Province>>> GetProvince() 
        {
            var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var userName = HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
            var roleName = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var customerVlue = HttpContext.User.FindFirst("CustomClaimType")?.Value;
            var key = HttpContext.User.FindFirst("Key")?.Value;
            ProvienceQueryCommand command = new ProvienceQueryCommand();
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取城市
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<T_City>>> GetCity(int provinceId)
        {
            CityQueryCommand command = new CityQueryCommand();
            command.ProvinceId = provinceId;
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取县
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<T_Contry>>> GetContry(int cityId)
        {
            CountryQueryCommand command = new CountryQueryCommand();
            command.CityId = cityId;
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPaging<UserDto>>> GetUserList([FromQuery] UserQueryCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPaging<T_Role>>> GetRoleList([FromQuery] RoleQueryCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MenberDto>>> GetUserName(int departmentId)
        {
            UserNameQueryCommand command = new UserNameQueryCommand();
            command.DeprtmentId = departmentId;
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取员工信息
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<UserNameDto>> GetUserNameDto(int rid)
        {
            UserRoleQueryCommand command = new UserRoleQueryCommand();
            command.Rid = rid;
            return mediator.Send(command);
        }
    }
}
